﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using System.Collections;
using System.Text;
using iTextSharp.text.xml;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using Generico.Coneccion;
using System.Data;
using RosarioFinanzas.ar.com.rofex.ws;


namespace RosarioFinanzas
{
    public partial class popPDF : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string accion = Request.QueryString["Accion"].ToString().Trim();
            string idmoneda = Request.QueryString["Moneda"].ToString().Trim();
            string txtFecha = Request.QueryString["Fecha"].ToString().Trim();
            string txtfechahasta = Request.QueryString["FechaHasta"].ToString().Trim();
            string banco1 = Request.QueryString["Banco1"].ToString().Trim();
            string banco2 = Request.QueryString["Banco2"].ToString().Trim();

            Response.Expires = 0;

            var a = createPDF(accion, idmoneda, txtFecha, txtfechahasta, banco1, banco2);
            byte[] byteArray = a.ToArray();
            int pdfSize = byteArray.Length;
            Response.ClearContent();
            Response.AppendHeader("content-length", pdfSize.ToString());
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "inline");
            Response.BinaryWrite(byteArray);
            Response.Flush();
            Response.Close();

        }
        private MemoryStream createPDF(string accion, string idmoneda, string txtfecha, string txtfechahasta, string banco1,string banco2)
        {

            MemoryStream msOutput = new MemoryStream();

            Document document = new Document(PageSize.A4, 30, 30, 30, 30);
            PdfWriter writer = PdfWriter.GetInstance(document, msOutput);
            document.Open();

            List<IElement> objects = null;
            switch (accion)
            {
                case "C":
                    objects = VerCotizaciones(idmoneda);

                    break;
                case "H":
                    objects = Historico(idmoneda, txtfecha);
                    break;
                case "HB":
                    objects = HistoricoBanco(idmoneda, txtfecha, txtfechahasta, banco1);
                    break;
                case "CH":
                    objects = Comparar(idmoneda, txtfecha, txtfechahasta, banco1,banco2);
                    break;
                case "R":
                    objects = IndiceRofex( idmoneda, txtfecha);
                    break;
                 case "M":
                    objects = IndiceMervaRos(idmoneda, txtfecha);
                    break;
                 case "BCR":
                    objects = PizarraBCRs();
                    break;
                 case "BCRH":
                    objects = BCRHistoticoDesdeHasta(idmoneda, txtfecha);
                    break;
                 case "BCRC":
                    objects = BCRComparacion(idmoneda, txtfecha);
                    break;
                 case "BCRH1":
                    objects = BCRHistorico(idmoneda);
                    break;
                    
            }



            foreach (IElement element in objects)
            {
                document.Add(element);
            }

            document.Close();

            return msOutput;
        }
        #region MONEDAS
        private List<IElement> VerCotizaciones()
        {
            try
            {
                String UrlDirectory = Request.Url.GetLeftPart(UriPartial.Path);
                UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/") + 1);

                string html = "";
                html += "<div  >";
                html += "<img src=\"" + UrlDirectory + "Imagenes/cabeceraNueva.png\"  width=534px />";
                html += "</div>";
                TextReader reader = new StringReader(html);
                StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
                styles.LoadStyle("CabeceraMoneda", HtmlTags.BGCOLOR, "#7f7f80");

                //styles.LoadStyle("DatoCompra", HtmlTags.BGCOLOR, "#7f7f80");


                //styles.LoadTagStyle(HtmlTags.DIV, HtmlTags.BGCOLOR, "blue");
                List<IElement> objects = HTMLWorker.ParseToList(reader, null);
                return objects;
            }
            catch (Exception e)
            {
                string html = e.Message;
                html += " PATH   " + this.Server.MapPath("Prueba");
                TextReader reader = new StringReader(html);
                List<IElement> objects = HTMLWorker.ParseToList(reader, null);
                return objects;
            }


        }
        public List<IElement> Historico(string idMoneda, string txtFecha)
        {
            String UrlDirectory = Request.Url.GetLeftPart(UriPartial.Path);
            UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/") + 1);

            var cn = new ClsConeccion();
            cn.Abrir();
            cn.AgregarParametros("intMoneda", Convert.ToInt32(idMoneda));
            var sqldr2 = cn.EjecutarSpDataReader("sp_ADM_GETCONFIGURACIONMONEDA");
            var dt1 = new DataTable();
            dt1.Load(sqldr2);
            string mon = dt1.Rows[0]["varMoneda"].ToString().ToUpper();
            string imgMoneda = dt1.Rows[0]["IMAGEN"].ToString();
            string colorCompra = dt1.Rows[0]["Color1"].ToString();
            string colorVenta = dt1.Rows[0]["Color2"].ToString();
            cn.Cerrar();

            cn = new ClsConeccion();
            cn.Abrir();

            cn.AgregarParametros("intMoneda", Convert.ToInt32(idMoneda));
            var sqldr = cn.EjecutarSpDataReader("sp_ADM_COTIZACIONESMONEDA");


            var dt = new DataTable();
            dt.Load(sqldr);

            string html = "";

            if (dt.Rows.Count > 0)
            {
                html += "<div  style=\"width:100%\">";
                html += "<img src=\"" + UrlDirectory + "Imagenes/cabeceraNueva.png\"  width=534px />";
                html += "</div>";
                html += "<table>";
                html += "<tr class=\"CabeceraMoneda\" > <td  colspan=\"4\" style=\"color: White;\"> cotización del día / " + mon + " </td></tr>";
                html += "<tr class=\"CabeceraMoneda\" > <td  style=\"text-align: center;\"> PROMEDIOS(*) </td> <td style=\"text-align: center;\"> COMPRA </td> <td style=\"text-align: center;\"> VENTA </td><td></td></tr>";
                for (int c = 0; c <= 1; c++)
                {
                    html += " <tr class=\"CabeceraMoneda\" > <td style=\" font-family:Arial; font-size:12px;width: 170px; bgcolor: " + colorCompra + " ; text-align: center; color: White;\">";
                    html += dt.Rows[c]["varbanco"].ToString();
                    html += " </td> <td style=\" font-size:12px; width: 60px;  text-align: center; color: White;\">";
                    html += dt.Rows[c]["monCompra"].ToString();
                    html += " </td> <td style=\"font-size:12px; width: 60px; text-align: center; color: White;\">";
                    html += dt.Rows[c]["monVenta"].ToString();
                    html += "</td><td style=\"font-size:10px;\">" + dt.Rows[c]["FECHA"].ToString().Substring(0, 10) + "</td></tr>";

                }
                html += "</table>";
                html += "<div id=\"datos\" style=\" font-family:Arial;margin-top: 0px;bgcolor: #f2f1ed; padding: 5px;\">";
                cn.Cerrar();
                cn = new ClsConeccion();
                cn.Abrir();
                cn.AgregarParametros("intMoneda", Convert.ToInt32(idMoneda));
                cn.AgregarParametros("datFechaDesde", Convert.ToDateTime(txtFecha + " 00:00:00"));
                cn.AgregarParametros("datFechaHasta", Convert.ToDateTime(txtFecha + " 23:59:59"));

                sqldr = cn.EjecutarSpDataReader("sp_ADM_COTIZACIONESMONEDAFecha");
                dt = new DataTable();
                dt.Load(sqldr);
                
                cn.Cerrar();
                
                if (dt.Rows.Count > 0)
                {

                    html += "<div  style=\"margin-top: 0px;background-color: #f2f1ed; padding: 5px 5px 5px 5px;\"> <div class=\"TituloDatos\">cotizaciones del día " + txtFecha + " " + mon + "</div>";
                    html += "<table><tr><td><img src=\"" + UrlDirectory + "Imagenes/fondoboton.png\"  width=534px height=1px /></td></tr></table>";
                    html += "<table style=\"width:100%;\">";
                    foreach (DataRow dr in dt.Rows)
                    {
                        html += "<tr>";
                        html += "<td style=\"height:40px;font-size:9px;\" >" + dr["varBanco"].ToString() + "</TD>";
                        html += "<td style=\"text-align:center;font-size:9px;\" > " + dr["monCompra"].ToString() + " </TD>";
                        html += "<td style=\"text-align:center;font-size:9px;\" > " + dr["monVenta"].ToString() + " </TD>";
                        html += "<td style=\"text-align:center;font-size:9px;\">" + dr["Fecha"].ToString().Substring(11, 5) + "</TD>";
                        html += "</tr>";
                        html += "<tr><td><img src=\"" + UrlDirectory + "Imagenes/fondoboton.png\"  width=534px height=1px /></td><td></td><td></td><td></td></tr>";
                    }
                    html += "</table>";
                    html += "</div>";
                    html += "</div>";
                }

            }
            else
            {

                html += "<div><br>";
                html += "NO EXISTEN DATOS PARA ESTE PERIODO </DIV>";

            }

            //            return html;
            TextReader reader = new StringReader(html);
            StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
            styles.LoadStyle("CabeceraMoneda", HtmlTags.BGCOLOR, "#7f7f80");
            styles.LoadStyle("TituloDatos", HtmlTags.COLOR, "#7f7f80");

            //styles.LoadStyle("DatoCompra", HtmlTags.BGCOLOR, "#7f7f80");


            //styles.LoadTagStyle(HtmlTags.DIV, HtmlTags.BGCOLOR, "blue");
            List<IElement> objects = HTMLWorker.ParseToList(reader, styles);
            return objects;
        }
        public List<IElement> HistoricoBanco(string idMoneda, string txtFechaDesde, string txtFechaHasta, string Banco1)
        {
            String UrlDirectory = Request.Url.GetLeftPart(UriPartial.Path);
            UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/") + 1);

            var cn = new ClsConeccion();
            cn.Abrir();
            cn.AgregarParametros("intMoneda", Convert.ToInt32(idMoneda));
            var sqldr2 = cn.EjecutarSpDataReader("sp_ADM_GETCONFIGURACIONMONEDA");
            var dt1 = new DataTable();
            dt1.Load(sqldr2);
            string mon = dt1.Rows[0]["varMoneda"].ToString().ToUpper();
            string imgMoneda = dt1.Rows[0]["IMAGEN"].ToString();
            string colorCompra = dt1.Rows[0]["Color1"].ToString();
            string colorVenta = dt1.Rows[0]["Color2"].ToString();
            cn.Cerrar();

            cn = new ClsConeccion();
            cn.Abrir();

            cn.AgregarParametros("intMoneda", Convert.ToInt32(idMoneda));
            var sqldr = cn.EjecutarSpDataReader("sp_ADM_COTIZACIONESMONEDA");


            var dt = new DataTable();
            dt.Load(sqldr);

            string html = "";

            if (dt.Rows.Count > 0)
            {
                html += "<div  style=\"width:100%\">";
                html += "<img src=\"" + UrlDirectory + "Imagenes/cabeceraNueva.png\"  width=534px />";
                html += "</div>";
                html += "<table>";
                html += "<tr class=\"CabeceraMoneda\" > <td  colspan=\"4\" style=\"color: White;\"> cotización del día / " + mon + " </td></tr>";
                html += "<tr class=\"CabeceraMoneda\" > <td  style=\"text-align: center;\"> PROMEDIOS(*) </td> <td style=\"text-align: center;\"> COMPRA </td> <td style=\"text-align: center;\"> VENTA </td><td></td></tr>";
                for (int c = 0; c <= 1; c++)
                {
                    html += " <tr class=\"CabeceraMoneda\" > <td style=\" font-family:Arial; font-size:12px;width: 170px; bgcolor: " + colorCompra + " ; text-align: center; color: White;\">";
                    html += dt.Rows[c]["varbanco"].ToString();
                    html += " </td> <td style=\" font-size:12px; width: 60px;  text-align: center; color: White;\">";
                    html += dt.Rows[c]["monCompra"].ToString();
                    html += " </td> <td style=\"font-size:12px; width: 60px; text-align: center; color: White;\">";
                    html += dt.Rows[c]["monVenta"].ToString();
                    html += "</td><td style=\"font-size:10px;\">" + dt.Rows[c]["FECHA"].ToString().Substring(0, 10) + "</td></tr>";

                }
                html += "</table>";
                html += "<div id=\"datos\" style=\" font-family:Arial;margin-top: 0px;bgcolor: #f2f1ed; padding: 5px;\">";
                cn.Cerrar();
                cn = new ClsConeccion();
                cn.Abrir();
                cn.AgregarParametros("moneda", (idMoneda));
                cn.AgregarParametros("Banco1", varbanco(Convert.ToInt32(Banco1)));
                cn.AgregarParametros("Desde", (FormatoAnsiFecha(txtFechaDesde) + " 00:00:00"));
                cn.AgregarParametros("Hasta", (FormatoAnsiFecha(txtFechaHasta) + " 23:59:59"));

                sqldr = cn.EjecutarSpDataReader("spGetHistorico");
                dt = new DataTable();
                dt.Load(sqldr);

                cn.Cerrar();

                if (dt.Rows.Count > 0)
                {
                    html += "<div  style=\"margin-top: 0px;background-color: #f2f1ed; padding: 5px 5px 5px 5px;\"> <div class=\"TituloDatos\">cotizaciones " + varbanco(Convert.ToInt32(Banco1)) + " /" + mon + "</div>";
                    html += "<table><tr><td><img src=\"" + UrlDirectory + "Imagenes/fondoboton.png\"  width=534px height=1px /></td></tr></table>";
                    html += "<table style=\"background-color: white;width:100%;\">";
                    foreach (DataRow dr in dt.Rows)
                    {
                        var dbVenta = (dr["Banco1Venta"] == Convert.DBNull) ? "" : Convert.ToDouble(dr["Banco1Venta"]).ToString("f3");
                        var dbCompra = (dr["Banco1Compra"] == Convert.DBNull) ? "" : Convert.ToDouble(dr["Banco1Compra"]).ToString("f3"); 
                        html += "<tr style=\"border-bottom:dotted 1px gray;\"> ";
                        html += "<td style=\"border-bottom:dotted 1px gray; height:18px;font-size:9px;\">" + varbanco(Convert.ToInt32(Banco1)) + "</TD>";
                        html += "<td style=\"border-bottom:dotted 1px gray; text-align:center;font-size:9px;\" > " + dbCompra  + " </TD>";
                        html += "<td style=\"border-bottom:dotted 1px gray; text-align:center;font-size:9px;\" > " + dbVenta + " </TD>";
                        html += "<td style=\"border-bottom:dotted 1px gray; text-align:center;font-size:9px;\">" + dr["Fecha"].ToString() + "</TD>";
                        html += "<tr><td><img src=\"" + UrlDirectory + "Imagenes/fondoboton.png\"  width=534px height=1px /></td><td></td><td></td><td></td></tr>";
                        html += "</tr>";
                    }
                    html += "</table></div>";

                }
                else
                {

                    html += "<div><br>";
                    html += "NO EXISTEN DATOS PARA ESTE PERIODO </DIV>";

                }
            }
            TextReader reader = new StringReader(html);
            StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
            styles.LoadStyle("CabeceraMoneda", HtmlTags.BGCOLOR, "#7f7f80");
            styles.LoadStyle("TituloDatos", HtmlTags.COLOR, "#7f7f80");
            
            List<IElement> objects = HTMLWorker.ParseToList(reader, styles);
            return objects;


        }
        public List<IElement> Comparar(string idMoneda, string txtFechaDesde, string txtFechaHasta, string Banco1, string Banco2)
        {
             String UrlDirectory = Request.Url.GetLeftPart(UriPartial.Path);
            UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/") + 1);

            var cn = new ClsConeccion();
            cn.Abrir();
            cn.AgregarParametros("intMoneda", Convert.ToInt32(idMoneda));
            var sqldr2 = cn.EjecutarSpDataReader("sp_ADM_GETCONFIGURACIONMONEDA");
            var dt1 = new DataTable();
            dt1.Load(sqldr2);
            string mon = dt1.Rows[0]["varMoneda"].ToString().ToUpper();
            string imgMoneda = dt1.Rows[0]["IMAGEN"].ToString();
            string colorCompra = dt1.Rows[0]["Color1"].ToString();
            string colorVenta = dt1.Rows[0]["Color2"].ToString();
            cn.Cerrar();

            cn = new ClsConeccion();
            cn.Abrir();

            cn.AgregarParametros("intMoneda", Convert.ToInt32(idMoneda));
            var sqldr = cn.EjecutarSpDataReader("sp_ADM_COTIZACIONESMONEDA");


            var dt = new DataTable();
            dt.Load(sqldr);

            cn.Cerrar();

            string html = "";

            if (dt.Rows.Count > 0)
            {
                html += "<div  style=\"width:100%\">";
                html += "<img src=\"" + UrlDirectory + "Imagenes/cabeceraNueva.png\"  width=534px />";
                html += "</div>";
                html += "<table>";
                html += "<tr class=\"CabeceraMoneda\" > <td  colspan=\"4\" style=\"color: White;\"> cotización del día / " + mon + " </td></tr>";
                html += "<tr class=\"CabeceraMoneda\" > <td  style=\"text-align: center;\"> PROMEDIOS(*) </td> <td style=\"text-align: center;\"> COMPRA </td> <td style=\"text-align: center;\"> VENTA </td><td></td></tr>";
                for (int c = 0; c <= 1; c++)
                {
                    html += " <tr class=\"CabeceraMoneda\" > <td style=\" font-family:Arial; font-size:12px;width: 170px; bgcolor: " + colorCompra + " ; text-align: center; color: White;\">";
                    html += dt.Rows[c]["varbanco"].ToString();
                    html += " </td> <td style=\" font-size:12px; width: 60px;  text-align: center; color: White;\">";
                    html += dt.Rows[c]["monCompra"].ToString();
                    html += " </td> <td style=\"font-size:12px; width: 60px; text-align: center; color: White;\">";
                    html += dt.Rows[c]["monVenta"].ToString();
                    html += "</td><td style=\"font-size:10px;\">" + dt.Rows[c]["FECHA"].ToString().Substring(0, 10) + "</td></tr>";

                }
                html += "</table>";
                html += "<div id=\"datos\" style=\" font-family:Arial;margin-top: 0px;bgcolor: #f2f1ed; padding: 5px;\">";

                cn = new ClsConeccion();
                cn.Abrir();
                cn.AgregarParametros("moneda", (idMoneda));
                cn.AgregarParametros("Banco1", varbanco(Convert.ToInt32(Banco1)));
                cn.AgregarParametros("Banco2", varbanco(Convert.ToInt32(Banco2)));
                cn.AgregarParametros("Desde", (FormatoAnsiFecha(txtFechaDesde) + " 00:00:00"));
                cn.AgregarParametros("Hasta", (FormatoAnsiFecha(txtFechaHasta) + " 23:59:59"));

                sqldr = cn.EjecutarSpDataReader("spGetComparacion");
                dt = new DataTable();
                dt.Load(sqldr);

                cn.Cerrar();

                if (dt.Rows.Count > 0)
                {
                    html += "<div  style=\"margin-top: 0px;background-color: #f2f1ed; padding: 5px 5px 5px 5px;\"> <div class=\"TituloDatos\">comparación de entidades " + " /" + mon + "</div>";
                    html += "<table><tr><td><img src=\"" + UrlDirectory + "Imagenes/fondoboton.png\"  width=534px height=1px /></td></tr></table>";
                    html += "<table style=\"background-color: white;width:100%;\">";
                    html += "<tr><td style=\"border-bottom:dotted 1px gray; height:18px;text-align:center;\" colspan=\"2\">" + varbanco(Convert.ToInt32(Banco1)) + "</td><td style=\"border-bottom:dotted 1px gray;text-align:center; height:18px;\" colspan=\"2\">" + varbanco(Convert.ToInt32(Banco2)) + "</td><td style=\"border-bottom:dotted 1px gray; height:18px;\"></td></tr>";
                    html += "<td style=\"border-bottom:dotted 1px gray; text-align:center;height:18px;\">" + "compra" + "</td>";
                    html += "<td style=\"border-bottom:dotted 1px gray;text-align:center; height:18px;\">" + "venta" + "</td>";
                    html += "<td style=\"border-bottom:dotted 1px gray;text-align:center; height:18px;\">" + "compra" + "</td>";
                    html += "<td style=\"border-bottom:dotted 1px gray; text-align:center;height:18px;\">" + "venta" + "</td>";
                    html += "<td style=\"border-bottom:dotted 1px gray;text-align:center; height:18px;\">" + "fecha" + "</td></tr>";
                    html += "<tr><td><img src=\"" + UrlDirectory + "Imagenes/fondoboton.png\"  width=534px height=1px /></td><td></td><td></td><td></td><td></td></tr>";
                    foreach (DataRow dr in dt.Rows)
                    {
                        html += "<tr style=\"border-bottom:dotted 1px gray;\"> ";
                        html += "<td style=\"border-bottom:dotted 1px gray; width:80px; text-align:center; height:18px;\">" + Convert.ToDouble(dr["Banco1Compra"]).ToString("f4") + "</td>";
                        html += "<td style=\"border-bottom:dotted 1px gray; width:80px; text-align:center;height:18px;\">" + Convert.ToDouble(dr["Banco1Venta"]).ToString("f4") + "</td>";
                        html += "<td style=\"border-bottom:dotted 1px gray; width:80px; text-align:center;height:18px;\">" + Convert.ToDouble(dr["Banco2Compra"]).ToString("f4") + "</td>";
                        html += "<td style=\"border-bottom:dotted 1px gray; width:80px; text-align:center; height:18px;\">" + Convert.ToDouble(dr["Banco2Venta"]).ToString("f4") + "</td>";
                        html += "<td style=\"border-bottom:dotted 1px gray; height:18px;\">" + dr["Fecha"].ToString().Substring(0, 10) + "</td>";
                        html += "</tr>";
                    }
                    html += "</table></div>";

                }
                else
                {

                    html += "<div><br>";
                    html += "NO EXISTEN DATOS PARA ESTE PERIODO </DIV>";

                }
            }
            TextReader reader = new StringReader(html);
            StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
            styles.LoadStyle("CabeceraMoneda", HtmlTags.BGCOLOR, "#7f7f80");
            styles.LoadStyle("TituloDatos", HtmlTags.COLOR, "#7f7f80");

            List<IElement> objects = HTMLWorker.ParseToList(reader, styles);
            return objects;

        }
        private List<IElement> VerCotizaciones(string idMoneda)
        {
            String UrlDirectory = Request.Url.GetLeftPart(UriPartial.Path);
            UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/") + 1);

            var cn = new ClsConeccion();
            cn.Abrir();
            cn.AgregarParametros("intMoneda", Convert.ToInt32(idMoneda));
            var sqldr2 = cn.EjecutarSpDataReader("sp_ADM_GETCONFIGURACIONMONEDA");
            var dt1 = new DataTable();
            dt1.Load(sqldr2);
            string mon = dt1.Rows[0]["varMoneda"].ToString().ToUpper();
            string imgMoneda = dt1.Rows[0]["IMAGEN"].ToString();
            string colorCompra = dt1.Rows[0]["Color1"].ToString();
            string colorVenta = dt1.Rows[0]["Color2"].ToString();

            cn.Cerrar();

            cn = new ClsConeccion();
            cn.Abrir();

            cn.AgregarParametros("intMoneda", Convert.ToInt32(idMoneda));
            var sqldr = cn.EjecutarSpDataReader("sp_ADM_COTIZACIONESMONEDA");

            string fondo = colorCompra;

            var dt = new DataTable();
            dt.Load(sqldr);

            cn.Cerrar();

            string html = "";

            if (dt.Rows.Count > 0)
            {
                html += "<div  style=\"width:100%\">";
                html += "<img src=\"" + UrlDirectory + "Imagenes/cabeceraNueva.png\"  width=534px />";
                html += "</div>";
                html += "<table>";
                html += "<tr class=\"CabeceraMoneda\" > <td  colspan=\"4\" style=\"color: White;\"> cotización del día / " + mon + " </td></tr>";
                html += "<tr class=\"CabeceraMoneda\" > <td  style=\"text-align: center;\"> PROMEDIOS(*) </td> <td style=\"text-align: center;\"> COMPRA </td> <td style=\"text-align: center;\"> VENTA </td><td></td></tr>";
                for (int c = 0; c <= 1; c++)
                {
                    html += " <tr class=\"CabeceraMoneda\" > <td style=\" font-family:Arial; font-size:12px;width: 170px; bgcolor: " + colorCompra + " ; text-align: center; color: White;\">";
                    html += dt.Rows[c]["varbanco"].ToString();
                    html += " </td> <td style=\" font-size:12px; width: 60px;  text-align: center; color: White;\">";
                    html += dt.Rows[c]["monCompra"].ToString();
                    html += " </td> <td style=\"font-size:12px; width: 60px; text-align: center; color: White;\">";
                    html += dt.Rows[c]["monVenta"].ToString();
                    html += "</td><td style=\"font-size:10px;\">" + dt.Rows[c]["FECHA"].ToString().Substring(0, 10) + "</td></tr>";

                }
                html += "</table></div>";
                html += "<div id=\"datos\" style=\" font-family:Arial;margin-top: 0px;bgcolor: #f2f1ed; padding: 5px;\">";
                for (int c = 2; dt.Rows.Count - 1 >= c; c++)
                {
                    html += "<div style=\"margin-top: 0px; bgcolor: #f2f1ed; padding-top: 0px; padding-bottom: 1px;\">";
                    html += "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"2\" style=\"bgcolor: white;border-style:solid;";
                    html += "border-width:3px; border-color:White;\"><tr><td style=\"font-size:10px; width: 167px; height: 10px; bgcolor: white; text-align: center;color: black;\">";

                    //html += "<a style=\"border:0;color:black;text-decoration:none;\" href=\"http://" + dt.Rows[c]["varlink"].ToString() + "\" class=\"show-tooltip\" title=\"" + dt.Rows[c]["varSucursal"].ToString() + "\">";
                    if (dt.Rows[c]["varimg"].ToString().Length > 0)
                    { html += "<img style=\"border:0;\" src=" + UrlDirectory + "Administracion/Logos/" + dt.Rows[c]["varimg"].ToString() + " width=150px/>"; }
                    else
                    { html += dt.Rows[c]["varbanco"].ToString(); }

                    string ColorVenta = "";
                    string ColorCompra = "";
                    if (DBNull.Value == dt.Rows[c]["promedioCompra"])
                    { ColorCompra = "#7f7f80"; }
                    else
                    {
                        //ColorCompra="#dfcf93";
                        ColorCompra = "#624036";
                    }

                    if (DBNull.Value == dt.Rows[c]["promedioVenta"])
                    { ColorVenta = "#7f7f80"; }
                    else
                    { ColorVenta = "#624036"; }


                    html += "</td><td class=\"DatoCompra\" style=\"font-size:9px;width: 55px; height: 10px; padding: 3px; text-align: center;color: black;\">";
                    html += dt.Rows[c]["monCompra"].ToString();
                    html += "</td><td style=\"font-size:9px;width: 55px; height: 10px; padding: 3px; text-align: center;color: black;\">";
                    html += dt.Rows[c]["monVenta"].ToString();
                    html += "</td><td style=\"font-size:9px;\">" + dt.Rows[c]["FECHA"].ToString() + "</td></tr></table></div>";
                    html += "<table><tr><td><img src=\"" + UrlDirectory + "Imagenes/fondoboton.png\"  width=534px height=1px /></td></tr></table>";

                }


            }
            html += "</div>";
            TextReader reader = new StringReader(html);
            StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
            styles.LoadStyle("CabeceraMoneda", HtmlTags.BGCOLOR, "#7f7f80");
            styles.LoadStyle("Linea", "border", "1");
            List<IElement> objects = HTMLWorker.ParseToList(reader, styles);
            return objects;

        }
        public static string varbanco(int idbanco)
        {
            if (idbanco == 0)
            {
                return "PROMEDIO ROSARIO FINANZAS";
            }
            if (idbanco == -1)
            {
                return "PROMEDIO SIMPLE";
            }

            var cn = new ClsConeccion();
            cn.Abrir();
            cn.AgregarParametros("idBanco", idbanco);
            var sqldr = cn.EjecutarSpDataReader("sp_ADM_GetBanco");
            var dt = new DataTable();
            dt.Load(sqldr);
            cn.Cerrar();
            return dt.Rows[0]["varBanco"].ToString();

        }
        public static string FormatoAnsiFecha(string fecha)
        {
            string anio = fecha.Substring(6, 4);
            string mes = fecha.Substring(3, 2);
            string dia = fecha.Substring(0, 2);
            fecha = anio + mes + dia;
            return fecha;

        }
        #endregion
        #region Rofex
        private static decimal unidadProducto(string idProducto)
        {
            switch (idProducto)
            {
                case "1":
                    return 30;
                case "2":
                    return 30;
                case "3":
                    return 30;
                case "6":
                    return 30;
                case "18":
                    return 1000;
                case "35":
                    return 1;
                case "40":
                    return 10;
                case "5":
                    return 5;
                case "45":
                    return 5;
            }
            return 1;

        }
        public List<IElement> IndiceRofex(string idProducto, string strProducto)
        {
            String UrlDirectory = Request.Url.GetLeftPart(UriPartial.Path);
            UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/") + 1);

            var obj = new ROFEXWebService();
            var ds = obj.MarketData(1, DateTime.Today, DateTime.Today, "", Convert.ToInt32(idProducto));


            string html = "";

            html += "<div  style=\"width:100%\">";
            html += "<img src=\"" + UrlDirectory + "Imagenes/cabeceraNueva.png\"  width=534px />";
            html += "</div>";
            html += "<table class=\"CabeceraMoneda\"> <tr> <td style=\"margin-top: 0px;margin-bottom: 2px;  font-family:Arial;";
            html += " padding-right: 15px; padding-left: 15px; padding-top: 0px;  line-height: 26px;  height: 26px; color:white; font-size:14px;\">";
            html += strProducto + "  /ROFEX  </td></tr></Table> ";
            html += "<div class=\"CabeceraMoneda\" style=\"margin-top: 0px;margin-bottom: 10px; background-color:#5a6845; height:2px;\"></div>";

            
            DataTable dt = new DataTable();
            dt.Columns.Add("Vencimiento", DateTime.Today.GetType());
            dt.Columns.Add("Posicion", "".GetType());
            dt.Columns.Add("Precio", 2.3.GetType());
            dt.Columns.Add("AjusteAnterior", 2.3.GetType());
            dt.Columns.Add("Variacion", 2.3.GetType());
            dt.Columns.Add("Volumen", 2.3.GetType());
            dt.Columns.Add("Fecha", DateTime.Today.GetType());

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                DataRow[] dr1 = ds.Tables[1].Select("Posicion = '" + dr["Posicion"].ToString() + "'");
                dt.Rows.Add(
                    dr["Vencimiento"],
                    dr["Posicion"],
                    dr1[0]["Precio"],
                    dr1[0]["AjusteAnterior"],
                    dr1[0]["Variacion"],
                    dr1[0]["Volumen"],
                    dr1[0]["Fecha"]
                    );
            }

            var Dia = DateTime.Today.DayOfWeek;
            var h = DateTime.Now.Hour;

            IEnumerable<DataRow> query = null;
            if (h >= 10 && h <= 18 && DayOfWeek.Saturday != Dia && DayOfWeek.Sunday != Dia)
            {
                query =
                from c1 in dt.AsEnumerable()
                where c1.Field<DateTime>("Fecha") >= DateTime.Today
                orderby c1.Field<DateTime>("Vencimiento") ascending
                select c1;
            }
            else
            {
                query =
                from c1 in dt.AsEnumerable()
                orderby c1.Field<DateTime>("Vencimiento") ascending
                select c1;
            }


            DataTable boundTable = query.CopyToDataTable<DataRow>();

            html += "<div style=\"margin-top: 0px; background-color: #f2f1ed; padding-top: 0px; padding-bottom: 0px;\">";
            html += "<table cellpadding=\"1\" cellspacing=\"2\" style=\"background-color: #f2f1ed;border-style:solid;";
            html += "border-width:3px; border-color:#f2f1ed;\">";
            html += "<tr><td style=\"width: 100px; height: 20px; text-align: center;color: black;font-size:10px;font-family:Arial;\">POSICION</TD>";
            html += "<td style=\"width: 70px; height: 20px; text-align: center;color: black;font-size:10px;font-family:Arial;\">PRECIO</TD>";
            html += "<td style=\"width: 80px; height: 20px; text-align: center;color: black;font-size:10px;font-family:Arial;\">AJUSTE ANT.</TD>";
            html += "<td style=\"width: 70px; height: 20px; text-align: center;color: black;font-size:10px;font-family:Arial;\">VARIACION</TD>";
            html += "<td style=\"width: 80px; height: 20px; text-align: center;color: black;font-size:10px;font-family:Arial;\">VARIACION %</TD>";
            html += "<td style=\"width: 70px; height: 20px; text-align: center;color: black;font-size:10px;font-family:Arial;\">VOLUMEN</TD>";
            html += "<td style=\"width: 80px;height: 20px; text-align: center;color: black;font-size:10px;font-family:Arial;\">FECHA</TD></tr></table>";
            html += "<table><tr><td><img src=\"" + UrlDirectory + "Imagenes/fondoboton.png\"  width=534px height=1px /></td></tr></table>";
            int c = 0;
            foreach (DataRow dr in boundTable.Rows)
            {
                if (dr["Volumen"].ToString().Length > 0 && Convert.ToDecimal(dr["Volumen"]) > 0)
                {
                    string Fecha_text = dr["Fecha"].ToString().Substring(0, 10);
                    var Posicion = dr["Posicion"].ToString();
                    var Precio = (dr["Precio"].ToString().Length > 0) ? (Convert.ToDecimal(dr["Precio"].ToString())).ToString("f4") : "---";
                    var AjusteAnterior = (dr["AjusteAnterior"].ToString().Length > 0) ? (Convert.ToDecimal(dr["AjusteAnterior"].ToString())).ToString("f4") : "---";
                    var Variacion = (dr["Variacion"].ToString().Length > 0) ? (Convert.ToDecimal(dr["Variacion"].ToString())).ToString("f4") + "" : "---";
                    string VariacionPorcentaje = "";

                    try
                    {
                        var decAjuste = (dr["AjusteAnterior"].ToString().Length > 0) ? Convert.ToDecimal(dr["AjusteAnterior"].ToString()) : 0;
                        var decPrecio = (dr["Precio"].ToString().Length > 0) ? Convert.ToDecimal(dr["Precio"].ToString()) : 0;
                        VariacionPorcentaje = ((decPrecio / decAjuste - 1) * 100).ToString("f2");
                    }
                    catch
                    {
                        VariacionPorcentaje = 0.ToString("f2");
                    }
                    //var decAjuste = (dr["AjusteAnterior"].ToString().Length > 0) ? Convert.ToDecimal(dr["Variacion"].ToString()) : 0;
                    //var decPrecio = (dr["Precio"].ToString().Length>0)?Convert.ToDecimal(dr["Precio"].ToString()):0;
                    //var VariacionPorcentaje = ((decPrecio / decAjuste - 1) * 100).ToString("f2"); 
                    var Volumen = (dr["Volumen"].ToString().Length > 0) ? (Convert.ToDecimal(dr["Volumen"].ToString()) / unidadProducto(idProducto)).ToString("N0") : "---";


                    html += "<div style=\"margin-top: 0px; background-color: #f2f1ed; padding-top: 5px; padding-bottom: 5px;\">";
                    html += "<table cellpadding=\"1\" cellspacing=\"2\" style=\"background-color: white;border-style:solid;";
                    html += "border-width:3px; border-color:White;\">";
                    html += "<tr><td style=\"width: 100px; height: 20px; background-color: white; text-align: center;color: black;font-size:10px;font-family:Arial;\">";
                    html += Posicion + "</td>";
                    html += "<td style=\"width:70px; height: 20px; background-color: #7f7f80;  text-align: center;color: black;font-size:10px;font-family:Arial;\">";
                    html += Precio + "</td>";
                    html += "<td style=\"width: 80px; height: 20px; background-color: silver; text-align: center;color: black;font-size:10px;font-family:Arial;\">";
                    html += AjusteAnterior + "</td>";
                    html += "<td style=\"width: 70px; height: 20px; background-color: silver; text-align: center;color: black;font-size:10px;font-family:Arial;\">";
                    html += Variacion + "</td>";
                    html += "<td style=\"width: 80px; height: 20px; background-color: silver; text-align: center;color: black;font-size:10px;font-family:Arial;\">";
                    html += VariacionPorcentaje + "</td>";
                    html += "<td style=\"width: 70px; height: 20px; background-color: silver; text-align: center;color: black;font-size:10px;font-family:Arial;\">";
                    html += Volumen + "</td>";
                    html += "<td style=\"width: 80px; height: 20px; background-color: white; text-align: center;color: black;font-size:10px;font-family:Arial;\">";
                    html += Fecha_text + "</td></tr></table></div>";
                    c++;
                }
            }
            html += "</div></div>";
            TextReader reader = new StringReader(html);
            StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
            styles.LoadStyle("CabeceraMoneda", HtmlTags.BGCOLOR, "#5a6845");
            styles.LoadStyle("Linea", "border", "1");
            List<IElement> objects = HTMLWorker.ParseToList(reader, styles);
            return objects;
            
        }

        #endregion
        #region MERVAROS
        public List<IElement> IndiceMervaRos(string idProducto, string strProducto)
        {
            try
            {
                string sql = "";
                if (idProducto == "1")
                {
                    sql = "Select PLAZO, convert(varchar(5), VTO  , 103)VTO,(convert(varchar(10), [Tasa Ult] * 100) + '%' )as [TASA ULT.],CONCERTADO ,";
                    sql += "  convert(varchar, Fecha  , 103) FECHA From dbo.MervaRosCauciones ";
                    sql += " Where intIndice = " + idProducto;
                    sql += " and Fecha = (Select max(fecha) from dbo.MervaRosCauciones where intIndice =  " + idProducto + ")";
                }
                else
                {
                    sql = "Select PLAZO, convert(varchar(5), VTO  , 103)VTO ,(convert(varchar(10), TasaMin * 100) + '%' )as [TASA MIN.],";
                    sql += "(convert(varchar(10), TasaMax * 100) + '%' )as [TASA MAX.],";
                    sql += "(convert(varchar(10), TasaPromedio * 100) + '%' )AS [TASA PROM.], Monto as [MONTO NOM.], ";
                    sql += " convert(varchar, Fecha  , 103) FECHA ";
                    sql += "From MervaRosCheques ";
                    sql += " Where intidIndice = " + idProducto;
                    sql += " and Fecha = (Select max(fecha) from dbo.MervaRosCheques where intidIndice =  " + idProducto + ")";
                }
                var cn = new ClsConeccion();
                cn.Abrir();
                var rd = cn.EjecutarSqlDataReader(sql);
                var dt = new DataTable();
                dt.Load(rd);

                cn.Cerrar();

                string html = "";
                String UrlDirectory = Request.Url.GetLeftPart(UriPartial.Path);
                UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/") + 1);
                html += "<div  style=\"width:100%\">";
                html += "<img src=\"" + UrlDirectory + "Imagenes/cabeceraNueva.png\"  width=534px />";
                html += "</div>";
                html += "<table class=\"CabeceraMoneda\"> <tr> <td style=\"margin-top: 0px;margin-bottom: 2px;  font-family:Arial;";
                html += " padding-right: 15px; padding-left: 15px; padding-top: 0px;  line-height: 26px;  height: 26px; color:white; font-size:14px;\">";
                html += strProducto + " /MERVAROS </td></tr></table> ";
                //html += "<div class=\"CabeceraMoneda\" style=\"margin-top: 0px;margin-bottom: 10px; background-color:#5a6845; height:2px;\"></div>";

               
               
                string alt = "";
                if (idProducto == "1")
                {
                    html += "<div style=\"padding: 0px 92px 0px 92px;\">";
                    alt = "100";
                }
                else
                {
                    html += "<div style=\"padding: 0px 12px 0px 12px;\">";
                    alt = "82";
                }

                html += "<table cellpadding=\"1\" cellspacing=\"4\" style=\"border-style:solid;";
                html += "border-width:3px; border-color:#f2f1ed;\"><tr>";
                foreach (DataColumn dc in dt.Columns)
                {
                    html += "<td style=\"width:82px; height: 20px; text-align: center;color: black; font-size:9px;font-family:Arial;\">" + dc.ColumnName + "</TD>";
                }
                //html += "<td style=\"height: 20px; text-align: center;color: black;\">FECHA</TD></tr></table>";
                html += "</tr></table>";
                html += "<table><tr><td><img src=\"" + UrlDirectory + "Imagenes/fondoboton.png\"  width=534px height=1px /></td></tr></table>";
                int c = dt.Columns.Count;

                foreach (DataRow dr in dt.Rows)
                {
                    html += "<div style=\"margin-top: 0px; background-color: #f2f1ed; padding-top: 5px; padding-bottom: 5px;\">";
                    html += "<table cellpadding=\"1\" cellspacing=\"4\" style=\"background-color:white ;border-style:solid;";
                    html += "border-width:3px; border-color:White;\"><tr>";
                    for (int i = 0; i < c; i++)
                    {

                        html += "<td style=\"width:82px; height: 20px;";
                        if (i == 0 || (idProducto == "1" && i == 4))
                        {
                            html += "background-color: white; color: black;";
                        }
                        if (i == 1)
                        {
                            html += "background-color: #58595B; color: black;";
                        }
                        if (i > 1 && ((idProducto == "1" && i != 4) || (idProducto != "1" && i != 6)))
                        {
                            html += "background-color: #DCDDDF; color: black;";
                        }
                        html += "font-size:9px;text-align: center;font-family:Arial;\">";

                        switch (dr[i].GetType().Name)
                        {
                            case "Decimal":
                                html += Convert.ToDecimal(dr[i]).ToString("#,##0.00");
                                break;
                            default:
                                html += dr[i];
                                break;

                        }


                        html += "</td>";

                    }
                    html += "</tr></table></div>";

                }
                html += "</div>";
                TextReader reader = new StringReader(html);
                StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
                styles.LoadStyle("CabeceraMoneda", HtmlTags.BGCOLOR, "#761210");
                styles.LoadStyle("Linea", "border", "1");
                List<IElement> objects = HTMLWorker.ParseToList(reader, styles);
                return objects;
            }
            catch (Exception e)
            {
                TextReader reader = new StringReader(e.Message);
                StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
                styles.LoadStyle("CabeceraMoneda", HtmlTags.BGCOLOR, "#761210");
                styles.LoadStyle("Linea", "border", "1");
                List<IElement> objects = HTMLWorker.ParseToList(reader, styles);
                return objects;
            }
        }

        #endregion
        #region BCR
        private List<IElement> PizarraBCRs()
        {
            string html = String.Empty;
            try
            {
                var cn = new ClsConeccion();
                cn.Abrir();
                string sql = "SELECT varDescripcion NOMBRE, MontoHoy HOY, MontoAyer AYER,case when MontoHoy > 0 then MontoHoy-MontoAyer else 0 end [VARIACION $],";
                sql += " case when MontoHoy > 0 then ((MontoHoy-MontoAyer)*100)/MontoHoy else 0 end [VARIACION %] FROM dbo.BCRCotizacion BCR";
                sql += " INNER JOIN (SELECT intIdIndice, max(Fecha) Fecha FROM BCRCotizacion";
                sql += " GROUP BY intIdIndice) AS B ON BCR.intIdIndice = B.intIdIndice AND BCR.Fecha = B.Fecha";
                sql += " INNER JOIN dbo.Indice I ON I.intIndice = BCR.intIdIndice";
                var sqldr2 = cn.EjecutarSqlDataReader(sql);
                var dt = new DataTable();
                dt.Load(sqldr2);
                cn.Cerrar();
                if (dt.Rows.Count > 0)
                {
                    String UrlDirectory = Request.Url.GetLeftPart(UriPartial.Path);
                    UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/") + 1);
                    html += "<div  style=\"width:100%\">";
                    html += "<img src=\"" + UrlDirectory + "Imagenes/cabeceraNueva.png\"  width=534px />";
                    html += "</div>";
                    html += "<table class=\"CabeceraMoneda\"> <tr> <td style=\"margin-top: 0px;margin-bottom: 2px;  font-family:Arial;";
                    html += " padding-right: 15px; padding-left: 15px; padding-top: 0px;  line-height: 26px;  height: 26px; color:white; font-size:14px;\">";
                    html += " BCR - Cotizaciones de pizarra </td></tr></table><table><tr> ";


                    foreach (DataColumn dc in dt.Columns)
                    {
                        html += "<td style=\"width:80px; height: 20px; text-align: center;color: black; font-size:9px;font-family:Arial;\">" + dc.ColumnName + "</TD>";
                    }
                    int c = dt.Columns.Count;
                    html += "</tr>";
                    html += "<tr><td colspan=\"" + c.ToString() + "\"><img src=\"" + UrlDirectory + "Imagenes/fondoboton.png\"  width=534px height=1px /></td></tr>";
                    foreach (DataRow dr in dt.Rows)
                    {
                        html += "<tr>";
                        for (int i = 0; i < c; i++)
                        {
                            html += "<td style=\"width:82px; height: 20px; background-color:";
                            switch (i)
                            {
                                case 1:
                                    html += "#2D2F44;";
                                    break;
                                case 2:
                                    html += "#2C8291;";
                                    break;
                                default:
                                    html += "#365C69;";
                                    break;

                            }

                            html += " font-size:10px;text-align: center;color: black;font-family:Arial;\">";
                            switch (dr[i].GetType().Name)
                            {
                                case "Decimal":
                                    html += Convert.ToDecimal(dr[i]).ToString("#,##0.0000");
                                    break;
                                default:
                                    html += dr[i];
                                    break;

                            }
                        }
                        html += "</tr>";
                    }

                    html += "</table>";
                    html += "</div>";
                }
                TextReader reader = new StringReader(html);
                StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
                styles.LoadStyle("CabeceraMoneda", HtmlTags.BGCOLOR, "#365C69");
                styles.LoadStyle("Linea", "border", "1");
                List<IElement> objects = HTMLWorker.ParseToList(reader, styles);
                return objects;
               
            }
            catch (Exception e)
            {
                TextReader reader = new StringReader(e.Message);
                StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
                styles.LoadStyle("CabeceraMoneda", HtmlTags.BGCOLOR, "#365C69");
                styles.LoadStyle("Linea", "border", "1");
                List<IElement> objects = HTMLWorker.ParseToList(reader, styles);
                return objects;
                
            }
        }

        private  string PizarraHistorica(DataTable dt)
        {
            String UrlDirectory = Request.Url.GetLeftPart(UriPartial.Path);
            UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/") + 1);
            string html = "";
            html += "<table  cellspacing=\"0\" style=\"background-color:white;width:100%;\"><tr class=\"PizarraTitulo\"><td>FECHA</TD><td>MAIZ DURO</TD><td>SOJA</TD><td>TRIGO</TD><td>GIRASOL</TD><td style=\"border-right-color:#7d7d7f;\">SORGO</TD> ";
            html += "<tr><td colspan=\"" + "6" + "\"><img src=\"" + UrlDirectory + "Imagenes/fondoboton.png\"  width=534px height=1px /></td></tr>";
            string fechaaux = "";
            foreach (DataRow dr in dt.Rows)
            {
                if (dr[0].ToString() != fechaaux)
                {
                    fechaaux = dr[0].ToString();
                    html += "</tr><tr class=\"PizarraDatos\"><td>" + fechaaux + "</td>";
                    html += "<td>" + Convert.ToDecimal(dr[2]).ToString("#,##0.0000") + "</td>";
                }
                else
                {
                    html += "<td>" + Convert.ToDecimal(dr[2]).ToString("#,##0.0000") + "</td>";
                }
            }
            html += "</tr></table>";
            return html;
        }
        public List<IElement> BCRHistoticoDesdeHasta(string txtFechaDesde, string txtFechaHasta)
        {
            var cn = new ClsConeccion();
            cn.Abrir();
            string sql = "SELECT  convert(varchar, Fecha  , 103) FECHA , varDescripcion NOMBRE, MontoHoy HOY, MontoAyer AYER ";
            sql += " FROM dbo.BCRCotizacion BCR";
            sql += " INNER JOIN dbo.Indice I ON I.intIndice = BCR.intIdIndice  where Fecha>='" + (FormatoAnsiFecha(txtFechaDesde) + " 00:00:00") + "' And Fecha<='" + (FormatoAnsiFecha(txtFechaHasta) + " 23:59:59") + "' order by Fecha desc";
            var sqldr2 = cn.EjecutarSqlDataReader(sql);
            var dt = new DataTable();
            dt.Load(sqldr2);
            cn.Cerrar();

            String UrlDirectory = Request.Url.GetLeftPart(UriPartial.Path);
            UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/") + 1);
            string html = "<div  style=\"width:100%\">";
            html += "<img src=\"" + UrlDirectory + "Imagenes/cabeceraNueva.png\"  width=534px />";
            html += "</div>";
            html += "<table class=\"CabeceraMoneda\"> <tr> <td style=\"margin-top: 0px;margin-bottom: 2px;  font-family:Arial;";
            html += " padding-right: 15px; padding-left: 15px; padding-top: 0px;  line-height: 26px;  height: 26px; color:white; font-size:14px;\">";
            html += " BCR - cotizaciones entre " + txtFechaDesde + " y " + txtFechaHasta + "</td></tr></table>";

            html += PizarraHistorica(dt);
            
            TextReader reader = new StringReader(html);
            StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
            styles.LoadStyle("CabeceraMoneda", HtmlTags.BGCOLOR, "#365C69");
            styles.LoadStyle("Linea", "border", "1");
            List<IElement> objects = HTMLWorker.ParseToList(reader, styles);
            return objects;
        }
        public List<IElement> BCRComparacion(string txtFechaDesde, string txtFechaHasta)
        {
            var cn = new ClsConeccion();
            cn.Abrir();
            string sql = "SELECT  convert(varchar, Fecha  , 103) FECHA , varDescripcion NOMBRE, MontoHoy HOY, MontoAyer AYER";
            sql += " FROM dbo.BCRCotizacion BCR";
            sql += " INNER JOIN dbo.Indice I ON I.intIndice = BCR.intIdIndice  where Fecha>='" + (FormatoAnsiFecha(txtFechaDesde) + " 00:00:00") + "' And Fecha<='" + (FormatoAnsiFecha(txtFechaDesde) + " 23:59:59") + "'";
            sql += " OR Fecha>='" + (FormatoAnsiFecha(txtFechaHasta) + " 00:00:00") + "' And Fecha<='" + (FormatoAnsiFecha(txtFechaHasta) + " 23:59:59") + "' order by Fecha desc";
            var sqldr2 = cn.EjecutarSqlDataReader(sql);
            var dt = new DataTable();
            dt.Load(sqldr2);
            cn.Cerrar();
            String UrlDirectory = Request.Url.GetLeftPart(UriPartial.Path);
            UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/") + 1);
            string html = "<div  style=\"width:100%\">";
            html += "<img src=\"" + UrlDirectory + "Imagenes/cabeceraNueva.png\"  width=534px />";
            html += "</div>";
            html += "<table class=\"CabeceraMoneda\"> <tr> <td style=\"margin-top: 0px;margin-bottom: 2px;  font-family:Arial;";
            html += " padding-right: 15px; padding-left: 15px; padding-top: 0px;  line-height: 26px;  height: 26px; color:white; font-size:14px;\">";
            html += " BCR - comparación del día " + txtFechaDesde + " y " + txtFechaHasta + "</td></tr></table>";
            html += PizarraHistorica(dt);
            TextReader reader = new StringReader(html);
            StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
            styles.LoadStyle("CabeceraMoneda", HtmlTags.BGCOLOR, "#365C69");
            styles.LoadStyle("Linea", "border", "1");
            List<IElement> objects = HTMLWorker.ParseToList(reader, styles);
            return objects;
        }
        public List<IElement> BCRHistorico(string txtFecha)
        {
            var cn = new ClsConeccion();
            cn.Abrir();
            string sql = "SELECT  convert(varchar, Fecha  , 103) FECHA , varDescripcion NOMBRE, MontoHoy HOY, MontoAyer AYER ";
            sql += " FROM dbo.BCRCotizacion BCR";
            sql += " INNER JOIN dbo.Indice I ON I.intIndice = BCR.intIdIndice  where Fecha>='" + (FormatoAnsiFecha(txtFecha) + " 00:00:00") + "' And Fecha<='" + (FormatoAnsiFecha(txtFecha) + " 23:59:59") + "' order by Fecha desc";
            var sqldr2 = cn.EjecutarSqlDataReader(sql);
            var dt = new DataTable();
            dt.Load(sqldr2);
            cn.Cerrar();
            String UrlDirectory = Request.Url.GetLeftPart(UriPartial.Path);
            UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/") + 1);
            string html = "<div  style=\"width:100%\">";
            html += "<img src=\"" + UrlDirectory + "Imagenes/cabeceraNueva.png\"  width=534px />";
            html += "</div>";
            html += "<table class=\"CabeceraMoneda\"> <tr> <td style=\"margin-top: 0px;margin-bottom: 2px;  font-family:Arial;";
            html += " padding-right: 15px; padding-left: 15px; padding-top: 0px;  line-height: 26px;  height: 26px; color:white; font-size:14px;\">";
            html += " BCR - cotización del día " + txtFecha + "</td></tr></table>";
            html += PizarraHistorica(dt);
            TextReader reader = new StringReader(html);
            StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
            styles.LoadStyle("CabeceraMoneda", HtmlTags.BGCOLOR, "#365C69");
            styles.LoadStyle("Linea", "border", "1");
            List<IElement> objects = HTMLWorker.ParseToList(reader, styles);
            return objects;
        }
        #endregion
    }
}
